package com.zzb.weikeautosign.client;

import org.apache.log4j.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * Created by zzb on 16/3/4.
 */
public class SocketClientReceiver extends Thread {
    private static Logger logger = Logger.getLogger(SocketClientReceiver.class);

    private Socket socket;

    public SocketClientReceiver(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        String ret = null;
        BufferedReader is =null;
        try {
            is = new BufferedReader(new InputStreamReader(socket.getInputStream(),"utf8"));
            while ((ret = is.readLine() )!= null){
                System.out.println(ret);
            }
        } catch (IOException e) {
            logger.error("连接关闭,接受消息失败");
        } finally {
            try {
                if(is != null)is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
